﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace testTennis
{
    class Set
    {
        public Game game = new Game();
        
        private int scoregameP1 = 0;
        private int scoregameP2 = 0;

        public string result = "";

        public int ScoregameP1
        {
            get { return scoregameP1; }
            set { scoregameP1 = value; }
        }

        public int ScoregameP2
        {
            get { return scoregameP2; }
            set { scoregameP2 = value; }
        }

        public void increasegame()
        {
            if(game.winner().Equals("P1"))
                ScoregameP1++;
            if (game.winner().Equals("P2"))
                ScoregameP2++;
        }

        public void winset()
        {
            while (scoregameP1 < 6 && scoregameP2 < 6)
            {
                increasegame();

            }

                if(scoregameP1 == 6 && scoregameP2 <= 4) 
                {
                    result = game.P1.getPlayerName(); 
                }
                    else if (scoregameP2 == 6 && scoregameP2 <= 4)
                            {
                                result = game.P2.getPlayerName();
                            }
            
            while((scoregameP1 >= 6 || scoregameP2 >= 6) && Math.Abs(scoregameP1-scoregameP2) < 2)
            {
                increasegame();
            }
                if (scoregameP1 > 6 && (scoregameP1 - scoregameP2) == 2)
                {
                    result = game.P1.getPlayerName();            
                }
                    else if (scoregameP2 > 6 && (scoregameP2 - scoregameP1) == 2)
                            {
                                result = game.P2.getPlayerName();
                            }
        }
    }
}
